import { deleteAction, getAction, httpAction, postAction, putAction } from '@/api/manage'
import Vue from 'vue'
import { UI_CACHE_DB_DICT_DATA } from '@/store/mutation-types'

//角色管理
const addRole = (params) => postAction("/sys/role/add", params);
const editRole = (params) => putAction("/sys/role/edit", params);
const checkRoleCode = (params) => getAction("/sys/role/checkRoleCode", params);
const queryall = (params) => getAction("/sys/role/queryall", params);
// 报表管理
const queryall2 = (params) => getAction("/reportForms/llbbReportForms/queryall", params);
// 法人管理
const queryBankReport2 = (params) => getAction("/juridicalPersonManage/llbbJuridicalPerson/queryJuridicalPersonReports", params);

//用户管理
const addUser = (params) => postAction("/sys/user/add", params);
const editUser = (params) => putAction("/sys/user/edit", params);
const queryUserRole = (params) => getAction("/sys/user/queryUserRole", params); const getUserList = (params) => getAction("/sys/user/list", params);
const frozenBatch = (params) => putAction("/sys/user/frozenBatch", params);
//验证用户是否存在
const checkOnlyUser = (params) => getAction("/sys/user/checkOnlyUser", params);
//改变密码
const changePassword = (params) => putAction("/sys/user/changePassword", params);

//权限管理
const addPermission = (params) => postAction("/sys/permission/add", params);
const editPermission = (params) => putAction("/sys/permission/edit", params);
const getPermissionList = (params) => getAction("/sys/permission/list", params);
const getSystemMenuList = (params) => getAction("/sys/permission/getSystemMenuList", params);
const getSystemSubmenu = (params) => getAction("/sys/permission/getSystemSubmenu", params);
const getSystemSubmenuBatch = (params) => getAction('/sys/permission/getSystemSubmenuBatch', params)
const queryTreeList = (params) => getAction("/sys/permission/queryTreeList", params);
const queryTreeListForRole = (params) => getAction("/sys/role/queryTreeList", params);
const queryListAsync = (params) => getAction("/sys/permission/queryListAsync", params);
const queryRolePermission = (params) => getAction("/sys/permission/queryRolePermission", params);
const saveRolePermission = (params) => postAction("/sys/permission/saveRolePermission", params);
// 角色报表管理
const queryRoleReport = (params) => getAction("/rolereport/llbbRoleReport/queryRoleReport", params);
const saveRoleReport = (params) => postAction("/rolereport/llbbRoleReport/saveRoleReport", params);
const queryTreeListForRole2 = (params) => getAction("/sys/role/queryTreeList2", params);
const queryPermissionsByUser = () => getAction("/sys/permission/getUserPermissionByToken");
const loadAllRoleIds = (params) => getAction("/sys/permission/loadAllRoleIds", params);
const getPermissionRuleList = (params) => getAction("/sys/permission/getPermRuleListByPermId", params);
const queryPermissionRule = (params) => getAction("/sys/permission/queryPermissionRule", params);

// 部门管理
const queryDepartTreeList = (params) => getAction("/sys/sysDepart/queryTreeList", params);
const queryDepartTreeSync = (params) => getAction("/sys/sysDepart/queryDepartTreeSync", params);
const queryIdTree = (params) => getAction("/sys/sysDepart/queryIdTree", params);
const queryParentName = (params) => getAction("/sys/sysDepart/queryParentName", params);
const searchByKeywords = (params) => getAction("/sys/sysDepart/searchBy", params);
const deleteByDepartId = (params) => deleteAction("/sys/sysDepart/delete", params);

//二级部门管理
const queryDepartPermission = (params) => getAction("/sys/permission/queryDepartPermission", params);
const saveDepartPermission = (params) => postAction("/sys/permission/saveDepartPermission", params);
const queryTreeListForDeptRole = (params) => getAction("/sys/sysDepartPermission/queryTreeListForDeptRole", params);
const queryDeptRolePermission = (params) => getAction("/sys/sysDepartPermission/queryDeptRolePermission", params);
const saveDeptRolePermission = (params) => postAction("/sys/sysDepartPermission/saveDeptRolePermission", params);
const queryMyDepartTreeList = (params) => getAction("/sys/sysDepart/queryMyDeptTreeList", params);

//日志管理
const deleteLog = (params) => deleteAction("/sys/log/delete", params);
const deleteLogList = (params) => deleteAction("/sys/log/deleteBatch", params);

//数据字典
const addDict = (params) => postAction("/sys/dict/add", params);
const editDict = (params) => putAction("/sys/dict/edit", params);
const treeList = (params) => getAction("/sys/dict/treeList", params);
const addDictItem = (params) => postAction("/sys/dictItem/add", params);
const editDictItem = (params) => putAction("/sys/dictItem/edit", params);

//表与字段树形结构
const queryTableTreeList = (params) => getAction("/paramConfig/ruleConfig/tableTreeList", params);
//查询表字段
const queryTableColumnList = (params) => getAction("/paramConfig/ruleConfig/queryTableColumnList", params);

//字典标签专用（通过code获取字典数组）
export const ajaxGetDictItems = (code, params) => getAction(`/sys/dict/getDictItems/${code}`, params);
//从缓存中获取字典配置
function getDictItemsFromCache(dictCode) {
  if (Vue.ls.get(UI_CACHE_DB_DICT_DATA) && Vue.ls.get(UI_CACHE_DB_DICT_DATA)[dictCode]) {
    let dictItems = Vue.ls.get(UI_CACHE_DB_DICT_DATA)[dictCode];
    //console.log("-----------getDictItemsFromCache----------dictCode="+dictCode+"---- dictItems=",dictItems)
    return dictItems;
  }
}

//系统通告
const doReleaseData = (params) => getAction("/sys/annountCement/doReleaseData", params);
const doReovkeData = (params) => getAction("/sys/annountCement/doReovkeData", params);
//获取系统访问量
const getLoginfo = (params) => getAction("/sys/loginfo", params);
const getVisitInfo = (params) => getAction("/sys/visitInfo", params);

// 根据部门主键查询用户信息
const queryUserByDepId = (params) => getAction("/sys/user/queryUserByDepId", params);

// 重复校验
const duplicateCheck = (params) => getAction("/sys/duplicate/check", params);
// 加载分类字典
const loadCategoryData = (params) => getAction("/sys/category/loadAllData", params);
const checkRuleByCode = (params) => getAction('/sys/checkRule/checkByCode', params)
//加载我的通告信息
const getUserNoticeInfo = (params) => getAction("/sys/sysAnnouncementSend/getMyAnnouncementSend", params);
const getTransitURL = url => `/sys/common/transitRESTful?url=${encodeURIComponent(url)}`

// a.获取所有法人信息:法人代码、法人名称
const queryBankNoCdList = (params) => getAction('/reportForms/llbbReportForms/queryBankNoCdList', params)
// b.获取所有角色信息:角色id、角色名称
// const queryRoleList = (params) => getAction('/reportForms/llbbReportForms/queryRoleList', params)
// c.获取所有主题信息:主题编码、主题名称
const queryThemeList = (params) => getAction('/reportForms/llbbReportForms/queryThemeList', params)
// d.根据报表代码获取所有该报表校验规则信息:规则编码、规则名称、规则描述
const queryRuleList = (params) => getAction('/reportForms/llbbReportForms/queryRuleList', params)
// 获取校验权限配置关系(get)
const queryVerificationAuthList = (params) => getAction('/verificationAuth/llbbVerificationAuth/queryVerificationAuthList', params)
// 所有报表
const getFormsList = (params) => getAction('/reportForms/llbbReportForms/list', params)
// 法人代码校验权限配置
const addAuth = (params) => postAction('/verificationAuth/llbbVerificationAuth/deploy', params)
// 法人代码校验权限配置_报文
const addMessDeploy = (params) => postAction('/verificationAuth/llbbVerificationAuth/messDeploy', params)
// 获取校验权限配置关系_报文(get)
const queryMessVerificationAuthList = (params) => getAction('/verificationAuth/llbbVerificationAuth/queryMessVerificationAuthList', params)
// e.获取机构树:机构编码、机构名称
// const queryNbjghList = (params) => getAction('/reportForms/llbbReportForms/queryNbjghList', params)
// 通过用户获取用户机构及其子机构信息(没有默认当前用户)
// 传参：用户账号-userName
const queryNbjghList = (params) => getAction('/rolereport/llbbRoleReport/getDepartsByUserName', params)
// f.根据报表代码获取所有表字段
const queryFieldsByReportCode = (params) => getAction('/reportForms/llbbReportForms/queryFieldsByReportCode', params)
// g.获取所有字典项信息:字段代码、名称
const getDictItem = (params) => getAction('/reportForms/llbbReportForms/getDictItem', params)
// h.根据报表代码查询权限列表:法人名称、角色名称、受控、分区、权限
const getRoleReport = (params) => getAction('/reportForms/llbbReportForms/getRoleReport', params)

// 根据报表代码查询分表字段
const getSplitTabField = (params) => getAction('/reportForms/llbbReportForms/getSplitTabField', params)
// 数据权限表-获取树形多选项
const getSplitTabRules = (params) => getAction('/reportForms/llbbReportForms/getSplitTabRules', params)
// 补录报表点击【分区分类】单选并且只能配置一项
const busTypeAuthAdd = (params) => postAction('/reportBusTypeAuth/llbbReportBusTypeAuth/add', params)
// 报表业务分类-通过补录报表代码查询
const getTypeAuth = (params) => getAction('/reportBusTypeAuth/llbbReportBusTypeAuth/queryByReportCode', params)
// 数据权限表-保存
const addLlbbRoleReport = (params) => postAction('/rolereport/llbbRoleReport/add', params)
// 数据权限表-编辑
const editLlbbRoleReport = (params) => putAction('/rolereport/llbbRoleReport/edit', params)
// 数据权限表-删除
const delLlbbRoleReport = (params) => deleteAction('/rolereport/llbbRoleReport/delete', params)
// 法人机构关系
// 保存(post)
const addDeploy = (params) => postAction('/jurPerOrgRelaAuth/llbbJurPerOrgRelaAuth/deploy', params)
// 获取法人机构关系(get)
// 传参：法人代码-bankNocd
const queryJurPerOrgRelaList = (params) => getAction('/jurPerOrgRelaAuth/llbbJurPerOrgRelaAuth/queryJurPerOrgRelaList', params)
// 数据分区字典
const loadTreeData = (params) => getAction('/sys/dict/loadTreeData', params)
// 报文权限表保存(post)
const addRoleMessage = (params) => postAction('/roleMessage/llbbRoleMessage/deploy', params)
// 报文权限表删除(post)
const deleteRoleMess = (params) => postAction('/roleMessage/llbbRoleMessage/deleteRoleMess', params)
// 报文权限表查询(get)
const queryRoleMessageList = (params) => getAction('/roleMessage/llbbRoleMessage/queryRoleMessageList', params)
// 报文权限表查询(get)
const queryMessageList = (params) => getAction('/llbbMessageForms/llbbMessageForms/list', params)
// 获取顶级机构下拉框
const getPraentDepartInfo = (params) => getAction('/reportForms/llbbReportForms/getPraentDepartInfo', params)
// 根据法人代码查询用户信息
// 传参：法人代码-bankNoCd
const queryRoleList = (params) => getAction('/reportForms/llbbReportForms/getUsersByBankNoCd', params)
// 首页接口
// ---------
// 处理数据任务-列表分页查询
// /llbbTaskCalendar/llbbTaskCalendar/clsjrwQueryList
// 传参:数据日期-sjrq
// 返回:任务报表(REPORTNAME)、数据日期(SJRQ)、任务截止日期(ENDDATE)、任务批次(taskBatchName)、剩余天数(surplusDays)、超期天数(overdueDays)、已完成(endNum)、未完成(noEndNum)
const clsjrwQueryList = (params) => getAction('/llbbTaskCalendar/llbbTaskCalendar/clsjrwQueryList', params)

// 生成数据任务-列表分页查询
// /llbbTaskCalendar/llbbTaskCalendar/scsjrwQueryList
// 传参:数据日期-sjrq
// 返回:报文名称(REPORTNAME)、数据日期(SJRQ)、任务截止日期(ENDDATE)、频度(frequencyName)、剩余天数(surplusDays)、超期天数(overdueDays)、已完成(endNum)、未完成(noEndNum)
const scsjrwQueryList = (params) => getAction('/llbbTaskCalendar/llbbTaskCalendar/scsjrwQueryList', params)
// 生成报文任务-列表分页查询
// /llbbTaskCalendar/llbbTaskCalendar/scbwrwQueryList
// 传参:数据日期-sjrq
// 返回:报文名称(REPORTNAME)、数据日期(SJRQ)、任务截止日期(ENDDATE)、频度(frequencyName)、剩余天数(surplusDays)、超期天数(overdueDays)、已完成(endNum)、未完成(noEndNum)、主题分类(themeName)
const scbwrwQueryList = (params) => getAction('/llbbTaskCalendar/llbbTaskCalendar/scbwrwQueryList', params)
//反馈处理任务-列表分页查询
const fkclrwQueryList = (params) => getAction('/llbbTaskCalendar/llbbTaskCalendar/fkclrwQueryList', params)
// 站内通告
// 列表：/llbbStationNotice/llbbStationNotice/list
const queryNoticeList = (params) => getAction('/llbbStationNotice/llbbStationNotice/list', params)
// 附件下载：llbbStationNotice/llbbStationNotice/downFile
const downFile = (params) => getAction('/llbbStationNotice/llbbStationNotice/downFile', params)
// 日历
const queryCalendar = (params) => getAction('/llbbTaskCalendar/llbbTaskCalendar/list', params)
// 查询所有报表(报表代码CKBX_CD_开头的)信息get请求: 
// /reportForms/llbbReportForms/queryall
// 报表访问路径：report_url 
// 报表代码:REPORTTYPECODE
// 报表名称:REPORTTYPENAME
// 查询所有报文(报表代码CKBX_P_开头的)跳转前端写死:/llbb/report/llbbMessageStatus/LlbbMessageStatusList
const queryAllReportForms = (params) => getAction('/reportForms/llbbReportForms/queryall', params)
// 待办任务
const queryAgencyTask = (params) => getAction('/llbbTaskCalendar/llbbTaskCalendar/queryAgencyTask', params)
const queryTaskCount = (params) => getAction('/llbbTaskCalendar/llbbTaskCalendar/queryTaskCount', params)


// 中转HTTP请求
export const transitRESTful = {
  get: (url, parameter) => getAction(getTransitURL(url), parameter),
  del: (url, parameter) => deleteAction(getTransitURL(url), parameter),
  post: (url, parameter) => postAction(getTransitURL(url), parameter),
  put: (url, parameter) => putAction(getTransitURL(url), parameter),
  http: (url, parameter) => httpAction(getTransitURL(url), parameter),
}

export {
  // imgView,
  // doMian,
  addRole,
  editRole,
  checkRoleCode,
  addUser,
  editUser,
  queryUserRole,
  queryBankReport2,
  getUserList,
  queryall,
  queryall2,
  frozenBatch,
  checkOnlyUser,
  changePassword,
  getPermissionList,
  addPermission,
  editPermission,
  queryTreeList,
  queryListAsync,
  queryRolePermission,
  queryRoleReport,
  saveRolePermission,
  saveRoleReport,
  queryPermissionsByUser,
  loadAllRoleIds,
  getPermissionRuleList,
  queryPermissionRule,
  queryDepartTreeList,
  queryDepartTreeSync,
  queryIdTree,
  queryParentName,
  searchByKeywords,
  deleteByDepartId,
  deleteLog,
  deleteLogList,
  addDict,
  editDict,
  treeList,
  addDictItem,
  editDictItem,
  doReleaseData,
  doReovkeData,
  getLoginfo,
  getVisitInfo,
  queryUserByDepId,
  duplicateCheck,
  queryTreeListForRole,
  queryTreeListForRole2,
  getSystemMenuList,
  getSystemSubmenu,
  getSystemSubmenuBatch,
  loadCategoryData,
  checkRuleByCode,
  queryDepartPermission,
  saveDepartPermission,
  queryTreeListForDeptRole,
  queryDeptRolePermission,
  saveDeptRolePermission,
  queryMyDepartTreeList,
  getUserNoticeInfo,
  getDictItemsFromCache,
  queryTableTreeList,
  queryTableColumnList,
  queryBankNoCdList,
  queryRoleList,
  queryThemeList,
  queryRuleList,
  queryNbjghList,
  queryFieldsByReportCode,
  getDictItem,
  getRoleReport,
  getFormsList,
  getSplitTabField,
  getSplitTabRules,
  busTypeAuthAdd,
  addLlbbRoleReport,
  getTypeAuth,
  editLlbbRoleReport,
  delLlbbRoleReport,
  addDeploy,
  queryJurPerOrgRelaList,
  addAuth,
  queryVerificationAuthList,
  loadTreeData,
  addRoleMessage,
  deleteRoleMess,
  queryRoleMessageList,
  addMessDeploy,
  queryMessVerificationAuthList,
  queryMessageList,
  getPraentDepartInfo,
  clsjrwQueryList,
  scsjrwQueryList,
  scbwrwQueryList,
  fkclrwQueryList,
  queryNoticeList,
  downFile,
  queryCalendar,
  queryAllReportForms,
  queryAgencyTask,
  queryTaskCount,
}



